package thread;

import java.util.concurrent.locks.ReentrantLock;

/**
 * date: 2023-2-21
 * ReentrantLock 的使用
 */
public class ThreadDemo30 {
    public static void main(String[] args) {
        ReentrantLock reentrantLock = new ReentrantLock(true); // 公平锁
        boolean result = reentrantLock.tryLock(); // 无参数版本，能加上锁就加，加不上就放弃
        try {

        } finally {
            if(result) { // 如果加上锁了就解锁
                reentrantLock.unlock();
            }
        }
    }
}
